<?php

namespace app\admin\controller\coupon;

use app\admin\traits\Curd;
use app\common\controller\AdminController;
use app\common\lib\Show;
use app\common\lib\Status;
use app\common\model\CouponReceive;
use think\App;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;

/**
 * @ControllerAnnotation(title="领取记录")
 */
class Receive extends AdminController
{

    use Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new CouponReceive();

    }
    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames(['title','openid'], 'r');
            $get = $this->request->get('', null, null);
            $filters = isset($get['filter']) && !empty($get['filter']) ? $get['filter'] : '{}';  //ca念书

            $filter = json_decode($filters, true);

            if (!empty($filter['title'])) {
                $where[] =["w.nickName", 'like', "%{$filter['title']}%"];
            }
            $row = $this->model
                ->field('r.id,r.coupon_id,r.openid as get_user,r.create_time,r.end_time,r.status')
                ->alias('r')
                ->join('weixin_user w','r.openid = w.openid')
                ->where($where)
                ->with(['coupon'])
                ->paginate($limit)
                ->toArray();
            return Show::json_show(Status::lay_normal,"ok",$row['data'],$row['total']);

        }
        return $this->fetch();
    }

    public function add()
    {
    }

    public function edit($id)
    {
    }
}